<template>
    <div class="img-list">
      <my-header myheader="图文资讯"></my-header>
      <div class="cate">
        <ul id="cateul">
          <li @click="Imgslist(0)"><span>全部</span></li>
          <li v-for="(itme,index) in Navlist" :key="index" @click="Imgslist(itme.id)"><span>{{itme.title}}</span></li>
        </ul>
      </div>
      <div class="img-list-box">
        <ul>
          <li v-for="itme in imgList" :key="itme.id">
            <router-link :to="`/img_list/${itme.id}/detail`"><img :src="itme.img_url" alt=""></router-link>
            <p>
              <span class="title">
                {{itme.title}}
                <br>
                {{itme.zhaiyao}}
              </span>
            </p>
          </li>
        </ul>
      </div>
    </div>
</template>

<script>
import MyHeader from '@/components/myheader'
import {getimgcategory, getimages} from '@/api/imgsApi'
export default {
  data () {
    return {
      Navlist: [],
      imgList: []
    }
  },

  components: {
    MyHeader
  },

  computed: {},

  mounted () {
    getimgcategory()
      .then(res => {
        if (res.status === 0) {
          // console.log(res)
          this.Navlist = res.message
          document.getElementById('cateul').style.width = (res.message.length + 1) * 60 + 'px'
        }
      })
    this.Imgslist(0)
  },

  methods: {
    // 图片列表数据
    Imgslist (cid) {
      let id = cid
      getimages(id)
        .then(res => {
          if (res.status === 0) {
            this.imgList = res.message
            console.log(res)
          }
        })
    }
  }
}

</script>
<style lang='scss' scoped>
.img-list {
    margin-bottom: 55px;
  }
  .cate {
    max-width: 100%;
    margin: 0;
    overflow-x:auto;
    overflow-y: hidden;
    font-size: 14px;
    ul {
      padding-left: 10px;
      margin: 5px 0;
      li {
        list-style: none;
        display: inline-block;
        padding: 0 0 0 5px;
        span {
          color:#0094ff;
        }
      }
    }
  }
  .img-list-box {
    ul {
      padding: 0;
      li {
        list-style: none;
        position: relative;
      }
    }
    p {
      font-size: 14px;
      color: #fff;
      position: absolute;
      bottom: 0px;
      left: 0px;
      background-color: rgba(0,0,0,0.4);
      .title {
        font-weight: bold;
      }
    }
    img {
      width: 100%;
    }
  }

  image[lazy=loading] {
    width: 100%;
    margin: auto;
  }
</style>
